Dreamweaver Article

How to Develop an Online Shopping Cart (Part One)


Table of Contents

  1. Introduction
  2. Cart Logic
  3. Data-Basics

Data Basics—It All Starts Here

The single most important component of an e-commerce site is the database. Yet, it is often the component that receives the least attention. It's a decision you are going to have to live with…for a long time!

You can develop the code on the front end, even the entire cart, with relative ease. You can even switch to an entirely different server model if you wish. But once you have thousands of records in your database and virtually your entire business is tied into it, changing your database becomes a job of epic proportions.

You may say, "But I'm a web developer, not a database programmer."

That may be true, but if you are developing e-commerce applications, you are going to have to know how a database works and how to work with them. This topic is enough to fill volumes, so I am only going to cover the basics. First, let's look at database types.

Database Types: Will That Be Filed Or Served?

There are basically two types of databases: file-based and server-based.

File-Based Databases

File-based databases are self-contained executables that run as stand-alone programs. A single compiled program contains the data, the UI to maintain the data, and the database engine to interpret queries and serve the data. Common file databases are Microsoft Access, FileMaker Pro, and Quarto Pro.

Strengths:

  • Cheap
  • Easy to run and learn
  • Portable

Weaknesses:

  • Not secure
  • Very limited capacity
  • Limited number of concurrent users
  • Only moderate data integrity
  • Can become very slow

Server-Based Databases

As the name indicates, these databases run on a server engine. The database or databases are not a part of the executable/server program itself. The data is served much the same way file sharing or web servers serve up files. Note: This is a very simplistic explanation. Common database servers include Microsoft SQL Server, MySQL, Oracle, Postgres, and Dbase.

Strengths:

  • Fast
  • High data capacity
  • Support for a large number of concurrent users
  • Greater data integrity
  • Very secure

Weaknesses:

  • More expensive
  • More complex
  • Less portable and must run on the database server

So which is the best choice? Well, before I get into that, let's look at something else: database structure. There are two general types of database structure. Again, remember, I speak in very general terms here.

Database Structure—Flat File Databases

The most basic of flat databases is a simple comma-delimited text file. And believe it or not, in some circumstances, this is all a site may need. A flat file database is similar to a spreadsheet that you would create in Microsoft Excel. A flat file database simply stores data in tables, columns, and rows. This may sound simple and ineffective, but one of the most popular databases on the web, MySQL, is a primarily flat file database.

Note: Version 4 has advanced in the area, but it still cannot be considered a true relational database.

Strengths:

  • Cheap
  • Small, very compressible
  • Fast
  • Most are fairly easy to administer and maintain

Weaknesses:

  • Force all SQL functions to be in the application
  • Do not support advanced database functions, such as views or stored procedures
  • Not as secure, or no security at all

Database Structure—Relational Databases

A relational database stores data in the exact same manner as a flat file database: in tables, columns, and rows. The big difference, however, is that you can establish relationships between the data in one table with the data in another table and enforce referential integrity to prevent lost or "orphan" data. These databases also allow you to internalize many of the functions you would otherwise have to program into your application, such as commonly used queries. This is far too deep a topic to cover here, but suffice it to say that relational databases are far more complex and powerful than their flat-file counterparts.

Strengths:

  • Fast very robust
  • High data capacity
  • Supports a large number of concurrent users
  • Greater data integrity
  • Very secure

Weaknesses

  • More expensive
  • More complex
  • Less portable, and must run on the database server
  • More difficult to maintain and administer

So which is the best choice? Which way should you lean?

Choosing What's Best For You: File Database or Database Server?

Let's help make this part a little easier. With the exception of Microsoft Access, all file databases are pretty much useless when it comes to delivering dynamic web content—in spite of what the ads might say. Save yourself a great deal of time and trouble and accept this fact right now.

Speaking of Microsoft Access, believe it or not, the most common database on the web is Microsoft Access. The database engine in Microsoft Access 2000 was significantly improved and for a small, low-traffic sites; Microsoft Access does an admirable job. Additionally, Access is a true relational database and supports views. But it has its limitations. It simply cannot handle heavy traffic. If your site traffic is likely to generate more than 20 concurrent database hits at a time, it's time to move to a database server like Oracle, SQL Server, or MySQL (if you don’t need a relational database). Generally, database servers are the way to go for the web.

So Which is It, Flat or Relational?

There are two things to consider when deciding on a database.

  1. Size: The number of records you will store in a database is a big concern. If you have just a few records or even a few hundred, and you know the size is will stay that way, a flat-file database will most likely work for you. If you are going to have thousands of records and the database will continue to grow, then look at a more powerful relational database.
  2. Traffic: In a site with heavy traffic, a relational database, especially a server-based one, such as SQL Server or Oracle or the like, can really speed up performance by internalizing many of the common queries and actions. You can perform a great deal of the maintenance and data compiling in advance and store it in memory.

Bring It Together

Now, with your database and your cart, the web has a brain. Your application can display products, and remember and record who your customers are and what they order. Take a look at the demo that you will build in part three of this article series to see a basic cart in action. You can find it here. The demo cart is written in ColdFusion and uses a Microsoft Access database, but the principles and logic involved are pretty much the same in any server language.

In part two of this article series, I will discuss the basics of business logic behind an online shopping cart, discuss accepting payments online, and security.